package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.SetmealDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.mapper.SetMealDishMapper;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * ClassName: SetMealController
 * Package: com.sky.controller.user
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/3/17  21:22
 * @Version 1.0
 */
@RestController("userSetMealController")
@Api(tags = "C-套餐相关接口")
@Slf4j
@RequestMapping("/user/setmeal")
public class SetMealController {

    @Autowired
 private SetmealService setmealService;
    @ApiOperation("根据分类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")//key = setmealCache::100
    public Result<List<Setmeal>> list(Long categoryId){
        log.info("根据分类id查询套餐{}",categoryId);
        //设置套餐只查询起售中套餐
        Setmeal setmeal = Setmeal.builder()
                .status(StatusConstant.ENABLE)
                .categoryId(categoryId)
                .build();
        List<Setmeal> list = setmealService.list(setmeal);
        return Result.success(list);
    }
    @ApiOperation("根据套餐id查询dish")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>>  dishList(@PathVariable Long id){
log.info("根据套餐id查询dish{}",id);
        List<DishItemVO> list =  setmealService.getDishItemBySetmealId(id);
        return Result.success(list);
    }
 }
